package com.gongda.gulimall.member.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gongda.gulimall.common.utils.PageUtils;
import com.gongda.gulimall.common.utils.Query;

import com.gongda.gulimall.member.dao.MemberDao;
import com.gongda.gulimall.member.entity.MemberEntity;
import com.gongda.gulimall.member.service.MemberService;


@Service("memberService")
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<MemberEntity> page = this.page(
//                new Query<MemberEntity>().getPage(params),
//                new QueryWrapper<MemberEntity>()
//        );
        String paramKey = (String)params.get("key");
        IPage<MemberEntity> page = this.page(
                new Query<MemberEntity>().getPage(params),
                new QueryWrapper<MemberEntity>()
                        .like(StringUtils.isNotBlank(paramKey),"username", paramKey)
                        .or()
                        .like(StringUtils.isNotBlank(paramKey),"id", paramKey)
                        .or()
                        .like(StringUtils.isNotBlank(paramKey),"nickname", paramKey)
        );
        return new PageUtils(page);
    }

}